package com.example.itshome.network;

import android.app.Activity;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public abstract class AbstractRecycleVIewGetRequest<T> extends AbstractNetworkRequest{

    protected AbstractRecycleVIewGetRequest(Activity activity) {
        super(activity);
    }

    protected AbstractRecycleVIewGetRequest(Activity activity, String method) {
        super(activity, method);
    }

    private List<T> currentData;
    private RecyclerView.Adapter<?> adapter;

    public AbstractRecycleVIewGetRequest<T> setCurrentData(List<T> currentData) {
        this.currentData = currentData;
        return this;
    }

    public AbstractRecycleVIewGetRequest<T> setAdapter(RecyclerView.Adapter<?> adapter) {
        this.adapter = adapter;
        return this;
    }

    protected void addItem(T item){
        currentData.add(item);
        adapter.notifyItemInserted(adapter.getItemCount()-1);
    }

    protected void removeAllItem(){
        adapter.notifyItemRangeRemoved(0,adapter.getItemCount());
        currentData.clear();
    }
}
